<!DOCTYPE html>
<html>
<head>
    <title>成果录入</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="">

    <link rel="stylesheet" href="dist/lib/weui.css">
    <link rel="stylesheet" href="dist/css/build.css">
    <link rel="stylesheet" href="dist/css/jquery-weui.css">
    <link href="dist/lib/imgUp.css?v2" rel="stylesheet"/>

    <style>
        body {
            background: #f5f5f5
        }

        .weui-cells.weui-cells_form {
            background: #fff;
            /*-moz-box-shadow: 2px 2px 5px #333333;*/
            /*-webkit-box-shadow: 0px 2px 15px #eee;*/
            /*box-shadow: 0px 2px 15px #eee;*/
            /*border-bottom: 1px solid #EDEDED;*/
        }

        .weui-uploader__input-box {
            margin-top: 5px;
        }

    </style>
</head>

<body>


<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">活动标题</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="title" value="请输入活动标题" type="text" disabled="disabled"
                   placeholder="请输入活动标题">
        </div>
    </div>
</div>
<div class="weui-cells__title">活动心得</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea class="weui-textarea" id="impression" placeholder="请输入活动心得" rows="3"></textarea>
            <!--<div class="weui-textarea-counter">-->
            <!--<span>0</span>/200-->
            <!--</div>-->
        </div>
    </div>
</div>

<div class="weui-cells__title">活动信息</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">活动人数</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="personnels" maxlength="5" value="" type="number"
                   placeholder="活动参与人数">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea class="weui-textarea" id="remark" placeholder="请输入活动信息" rows="3"></textarea>
            <!--<div class="weui-textarea-counter">-->
            <!--<span>0</span>/200-->
            <!--</div>-->
        </div>
    </div>
</div>


<div class="weui-cells__title">活动图片</div>
<div class="weui-cells weui-cells_form">

    <div class="weui-cell">
        <div class="weui-cell__bd">
            <div class="weui-uploader">
                <div class="weui-uploader__bd">
                    <ul class="z_photo upimg-div clear">
                        <li class="z_file fl">
                            <div class="add-img weui-uploader__input-box"></div>
                            <input type="file" name="file" id="file" class="file" value="" placeholder="4"
                                   accept="image/*" multiple/>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="postActivity">确认提交</a>
</div>

<script src="dist/lib/jquery-2.1.4.js"></script>
<script src="dist/lib/fastclick.js"></script>
<script>
    $(function () {

        FastClick.attach(document.body);

        $("#beginDate").calendar({
            // container:'请选择'

            onChange: function (p, values, displayValues) {
                console.log(values, displayValues);
            }
        });
        $("#endDate").calendar({
            onChange: function (p, values, displayValues) {
                console.log(values, displayValues);
            }
        });

    });
</script>

<script src="dist/js/jquery-weui.js"></script>
<script src="dist/lib/vue.min.js"></script>
<script src="dist/lib/http.js"></script>
<script src="dist/lib/imgUp.js"></script>
<script src="dist/lib/jquery.cookie.js"></script>

<script>

    $http.getUserSignIn(true, 'activity_result.html');

    var list = JSON.parse($.cookie('resultID'));
    // $(document).attr("title", '成果录入: ' + list.title);
    // $("#title").attr("value", list.title);


    /**
     * js获取HTML ？后面传值
     */
    function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                // theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
                theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    /**
     * js获取HTML ？后面传值 的调用方法
     */
    var Request = new Object();
    Request = GetRequest();
    var id;
    id = Request['id'];

    $(document).attr("title", '成果录入: ' + Request['title']);
    $("#title").attr("value", Request['title']);


    $(document).on("click", "#postActivity", function () {
        var title = $('#title').val();
        var impression = $('#impression').val();
        var remark = $('#remark').val();
        var img = getValues('imgFile');
        var personnels = $('#personnels').val();

        if (img == '') {
            $.toptip('请上传活动照片');
            return;
        }

        var rs = {
            id: id,
            // title: Request['title'],
            impression: impression,//成果
            remark: remark,
            photoAchievementUrl: img,
            personnels: personnels,//参加人数
            wechatId: $http.getUserSignIn().wechatId
        };
        console.log(rs)

        $http.post($http.postInputInformation(rs)).then(function (data) {
            if (data.success == true) {
                $.alert(data.message, '提示', function () {
                    $.cookie('activity', $http.getCookieArray(list.id, list.title));
                    // window.location.href = 'activity_details.html';
                    openDetails(id, Request['title'])
                })

            }
        }, function (err) {
            console.log(err);
            return err;
        });


    });

    function getValues(inputName) {
        var values = [];
        $('input[name=' + inputName + ']').each(function (i, v) {
            values.push(v.value);
        })
        return values.join(',');
    }

    /**
     * 打开详情
     * @param id
     * @param title
     */
    function openDetails(id, title) {

        // $.cookie('documentID', $http.getCookieArray(id, title));
        window.location.href = 'activity_details.html?id=' + id + '&title=' + title;
    }


</script>
</body>
</html>
